<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/2
 * Time: 10:07
 */

namespace app\admin\controller\hotel;


use app\admin\controller\BaseController;
use app\admin\model\HouseOrder;
use app\admin\model\StoreInfo;
use app\admin\model\User;
use think\Session;
use think\Controller;

class Order extends BaseController
{
    public function page(){
        $hOrder=new HouseOrder();
        $user=(new Session())->get("user");
        if($user["scope"]==0){
            $items=$hOrder->where([
                "is_del"        =>0,
                "uid"           =>$user["id"]
            ])->with([
                "house","user"
            ])->paginate(15);
        }else{
            $items=$hOrder->where("is_del",0)->with([
                "house","user"
            ])->paginate(15);
        }

        $page=$items->render();
        $this->assign("items",$items);
        $this->assign("page",$page);
        return $this->fetch("index");
    }

    //入住
    public function checkIn(){
        $id=$this->request->param("id");
        $hOrder=HouseOrder::get($id);
        $hOrder->order_status=3;
        $hres=$hOrder->house->status=2;
        $hOrder->house->save();
        $ores=$hOrder->save();
        if($ores&&$hres){
            $this->success("success");
        }
        $this->error("fail");
        
    }

    //取消订单
    public function cancel(){
        $hOrder=new HouseOrder();
        $data=$this->request->param();
        $data["order_status"]=0;
        $res=$hOrder::update($data);
        if($res){
            $this->success("success");
        }
        $this->error("success");
    }

    //删除订单
    public function del(){
        $hOrder=new HouseOrder();
        $data=$this->request->param();
        $data["is_del"]=1;
        $res=$hOrder::update($data);
        if($res){
            $this->success("success");
        }
        $this->error("success");
    }

    //选择商家
    public  function  chooseStore(){
        $store=new StoreInfo();
        $items=$store->paginate(15);
        $page=$items->render();
        $this->assign("page",$page);
        $this->assign("items",$items);
        return $this->fetch("store");
    }
    //选择用户
    public  function  chooseUser(){
        $user=new User();
        $items=$user->paginate(15);
        $page=$items->render();
        $this->assign("page",$page);
        $this->assign("items",$items);
        return $this->fetch("user");
    }
}